package com.codeforces.gym.g100142;

import java.io.File;
import java.io.FileWriter;
import java.math.BigInteger;
import java.util.Scanner;

public class D {
	
	static BigInteger A, B, C, tmp;
	static BigInteger two = new BigInteger("2");

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("nosimple.in"));
		FileWriter writer = new FileWriter(new File("nosimple.out"));
		
		A = scanner.nextBigInteger();
		B = scanner.nextBigInteger();
		C = scanner.nextBigInteger();
		tmp = BigInteger.ONE;
		
		while (B.compareTo(BigInteger.ONE) > 0) {
			if (B.mod(two).compareTo(BigInteger.ZERO) != 0) {
				tmp = tmp.multiply(A).mod(C);
			}
			B = B.divide(two);
			A = A.multiply(A).mod(C);
		}
		A = A.multiply(tmp).mod(C);
		writer.write(A.toString());
		writer.close();
	}

}
